package system

import (
	"io/ioutil"

	"github.com/go-yaml/yaml"
)

/**
* Created by LONG  on 2018/5/25.
 */

type Configuration struct {
	SignupEnabled bool   `yaml:"signup_enabled"` // signup enabled or not
	SmtpUsername  string `yaml:"smtp_username"`  // username
	SmtpPassword  string `yaml:"smtp_password"`  //password
	SmtpHost      string `yaml:"smtp_host"`      //host
	SessionSecret string `yaml:"session_secret"` //session_secret
	Public        string `yaml:"public"`         //public
	Addr          string `yaml:"addr"`           //addr
	DSN           string `yaml:"dsn"`            //database dsn
	Mode          string `yaml:"mode"`           //Mode
	Dbprefix      string `yaml:"Dbprefix"`       //Dbprefix
	CookieTime    string `yaml:"cookietime"`
	Storage       string `yaml:"storage"` //存取方式
	MongoDsn      string `yaml:"mongodsn"`
}

var configuration *Configuration

func LoadConfiguration(path string) error {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return err
	}
	var config Configuration
	err = yaml.Unmarshal(data, &config)
	if err != nil {
		return err
	}
	configuration = &config
	return err
}

func GetConfiguration() *Configuration {
	return configuration
}
